package com.szms.mobile.service.impl;

import android.content.Context;

import com.szms.mobile.dto.ResultDto;
import com.szms.mobile.enums.SystemConstants;
import com.szms.mobile.repository.SysCfgRepository;
import com.szms.mobile.repository.model.SysCfgModel;
import com.szms.mobile.service.SysCfgService;

import java.util.List;

public class SysCfgServiceImpl extends BaseImpl implements SysCfgService {
    SysCfgRepository repository;

    public SysCfgServiceImpl(Context _context) {
        super(_context);
        repository = new SysCfgRepository(context);
    }

    @Override
    public ResultDto<String> getHost() {
        List<SysCfgModel> host = repository.query("cfg_key=?", new String[]{SystemConstants.RemoteHost.getCode()});

        if (host.size()==0 ){
            return ResultDto.error("请配置主机");
        }

        String hostUrl = host.get(0).getConfigValue();
        return ResultDto.success(hostUrl);
    }

    @Override
    public ResultDto<Integer> getPort() {
        List<SysCfgModel> port = repository.query("cfg_key=?", new String[]{SystemConstants.RemotePort.getCode()});

        if (port.size()==0){
            return ResultDto.error("请配置端口");
        }

        String portStr = port.get(0).getConfigValue();
        Integer p = new Integer(portStr);
        return ResultDto.success(p);
    }


}
